// pages/project/detail/detail.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

    is_submit: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    var projectId = options.id
    var num = options.num
    console.log(projectId)
    this.setData({
      projectId: projectId,
      num: num
    })
    this.getProjectInfo(projectId)
  },

  getProjectInfo: function (projectId) {
    wx.showLoading({
      title: '加载中',
    })
    var that = this
    // var projectId = that.data.projectId
    wx.request({
      url: app.host + '/project/info/' + projectId,
      method: 'get',
      header: {
        accessToken: app.accessToken
      },
      complete: function(res) {
        wx.hideLoading()
        console.log(res)
        if (res.statusCode == 200) {
          if (res.data.code == 0) {
            that.setData({
              projectInfo: res.data.data
            })
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
          }
        } else {
          wx.showToast({
            title: '无法连接服务器',
            icon: 'none'
          })
        }
      }
    })
  },

  submit: function(e) {
    if (this.data.is_submit == true){
      wx.showToast({
        title: "已申请报名",
        icon: 'none'
      })
      return ;
    }
    console.log(e)
    var that = this
    var projectId = that.data.projectId
    wx.request({
      url: app.host + '/projectStaff/info',
      method: 'post',
      header: {
        accessToken: app.accessToken
      },
      data: {
        projectInfoId: projectId
      },
      complete: function(res) {
        console.log(res)
        if (res.statusCode == 200) {
          if (res.data.code == 0) {
            wx.showToast({
              title: "提交报名申请成功",
              icon: 'none'
            })
            that.setData({
              is_submit:true
            })
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'none'
            })
          }
        } else {
          wx.showToast({
            title: '无法连接服务器',
            icon: 'none'
          })
        }
      }
    })

  },
  toHome:function(e){
    wx.reLaunch({
      url: '/pages/index/index',
    })
  }




})